home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 8 / Power CD-ROM 8.iso / prgmming / oldutil / trunc.asm < prev    next >
Encoding:
Assembly Source File  |  1994-12-10  |  2.9 KB  |  121 lines

  1.     Name trunc
  2.     Title
  3.     page    ,132
  4. comment /
  5.  
  6.     This program is a filter that reads a file and truncates each
  7.     line at the character on the parmline or the eol char <CR>.
  8.     If there is not parameter lines will be truncated at the first
  9.     space (which includes leading spaces as well.)
  10.  
  11. /
  12. ;===================================================================
  13. code    segment    public
  14. ;===================================================================
  15. ;
  16. ;    command line is at 80h of psp - first byte is length
  17. ;
  18.     org    80h
  19. parmsize    db    ?
  20. parm        db    7fh dup (?)
  21. ;
  22. ; .com starts at 100h - but must jump around any data area
  23. ;
  24.     org    100h            ; com file starts here
  25.     assume    cs:code,ds:code,es:code
  26. trunc:
  27.     jmp    clear
  28. ;===================================================================
  29. ;
  30. ; data area for .com programs
  31. ; Uncomment (**) statements and comment (&&) statements
  32. ; if you need two different buffers.
  33. ;
  34. inchar      db    ?
  35. ;
  36. ;===================================================================
  37. clear:
  38. ;
  39. ; start of actual code is here (clear)
  40. ;
  41.     mov    ah,30h        ; get dos version
  42.     int    21h
  43.     cmp    al,2        ; must be at least 2.0
  44.     jb    oops
  45. ;
  46. ; release uneeded memory
  47. ;
  48.     mov    bx,offset bos[256]    ; 256 byte local stack
  49.     mov    sp,bx
  50.     mov    cx,4
  51.     sar    bx,cl
  52.     inc    bx        ; paragraphs needed = end/16 + 1
  53.     mov    ah,4ah        ; SETBLOCK
  54.     int    21h
  55. ;
  56. ; Read a character.  If it compares to the current character of the
  57. ; parmline, loop through the end of the line (CR/LF).
  58. ;
  59. ; Check parameter line for a character.  If none, insert a space.
  60. ;
  61.     cmp    parmsize,2h    ; if no characters, insert a space.
  62.     jge    parmok
  63.     mov    parm+1,' '    ; tack on the space
  64.  
  65. ; These two i/o parameters are constants.
  66. ;
  67. parmok:
  68.     mov    dx,offset inchar
  69.     mov    cx,1h        ; get 1 character
  70. again:
  71. ;
  72. ; read a character
  73. ;
  74.     xor    bx,bx        ; zero is handle of standard input
  75.     mov    dx,offset inchar
  76.     mov    ah,3fh        ; read a file/device function
  77.     int    21h        ; invoke the function
  78. ;
  79. ; if carry set of ax=0 exit
  80. ;
  81.     jc    oops        ; i/o error
  82.     and    ax,ax        ; set flags
  83.     jz    oops        ; eof
  84. ;
  85. ; compare character against parmline.
  86. ;
  87.     mov    al,parm+1    ; load character
  88.     cmp    al,inchar
  89.     jne    output        ; if characters don't match, output
  90. ;
  91. ; Character matched - now read characters until <cr> is seen.
  92. ;
  93. skip:
  94.     xor    bx,bx        ; zero is handle of standard input
  95.     mov    cx,1h        ; get 1 character
  96.     mov    ah,3fh        ; read a file/device function
  97.     int    21h        ; invoke the function
  98. ;
  99. ; if carry set of ax=0 exit
  100. ;
  101.     jc    oops        ; i/o error
  102.     and    ax,ax        ; set flags
  103.     jz    oops        ; eof
  104. ;
  105. ; look for <cr>
  106. ;
  107.     cmp    inchar,0dh    ; if inchar is <cr>, start i/o again.
  108.     jne    skip        ; otherwise skip it.
  109. output:
  110.     mov    bx,1h        ; standard output handle
  111.     mov    ah,40h        ; dx still points at inchar
  112.     int    21h        ; call dos output function
  113.     jmp    again        ; repeat cycle
  114. oops:
  115.     int    20h        ; return to dos
  116.  
  117. bos    label    near        ; bottom of stack
  118.  
  119. code    ends
  120.     end    trunc
  121.